#include <iostream>
#include <string>
#include <pthread.h>
#include <unistd.h>
#include "BlockQueue.hpp"
#include"Task.hpp"
using namespace std;
void *productRoutine(void *arg)
{
     BlockQueue<Task>*td=(BlockQueue<Task>*)arg;
     while(true)
     {
    int data1=rand()%10;
    sleep(1);
    int data2=rand()%10;
    sleep(1);
    char oper=operachar[rand()%operachar.size()];
    Task t(data1,data2,oper);
    cout<<"productor task";
    t.prdduct();
    td->push(t);
    sleep(1);
     }
    return nullptr;

}
void *customRoutine(void *arg)
{
    BlockQueue<Task>*td=(BlockQueue<Task>*)arg;
while(true)
{
     Task t;
    td->pop(&t);
    t();
    cout<<"consumer data";
    t.custom();
}
    return nullptr;
}
int main()
{
    // pthread_t t1, t2;
    // BlockQueue<int> *td = new BlockQueue<int>();
    // pthread_create(&t1, nullptr, productRoutine, td);
    // pthread_create(&t2, nullptr, productRoutine, td);
    // pthread_join(t1, nullptr);
    // pthread_join(t2, nullptr);
    srand((size_t)time(nullptr) ^ getpid() ^ pthread_self());
        pthread_t c1, p1;
    BlockQueue<Task> *td = new BlockQueue<Task>();
    pthread_create(&c1, nullptr, customRoutine, td);
    pthread_create(&p1, nullptr, productRoutine, td);
    pthread_join(c1, nullptr);
    pthread_join(p1, nullptr);
    return 0;
}